<?php

/**

 * Created by PhpStorm.

 * User: jingshou

 * Date: 2017/9/17

 * Time: 23:57

 */



namespace app\mobile\model;



use think\Model;

use think\Session;



class CaseModel extends Model

{

    protected $table = 'tp_case';



    public function getTypeNameAttr()

    {

        $typeInfo = TypeModel::get($this->typeId);

        return !empty($typeInfo) ? $typeInfo->typeName : '';

    }



    public function getList($typeId, $count = 10)

    {

        if (empty($typeId)) {

            return self::where(['state' => 1])

                ->order('sort asc')

                ->paginate($count);

        } else {

            return self::where([ 'state' => 1, 'typeId' => $typeId])

                ->order('sort asc')

                ->paginate($count);

        }

    }



    public function getInfo($id)

    {

        return self::where([ 'id' => $id])

            ->order('id asc')->limit(1)->find();

    }



    public function getPre($id, $typeId)

    {

        return self::where(['id' => ['>', $id], 'typeId' => $typeId])

            ->order('id asc')->limit(1)->find();

    }



    public function getNext($id, $typeId)

    {

        return self::where([ 'id' => ['<', $id], 'typeId' => $typeId])

            ->order('id asc')->limit(1)->find();

    }



    public function getListAll($count = 12)

    {

        return self::where([ 'state' => 1])

            ->order('sort desc')

            ->paginate($count);

    }

}